package com.zackratos.kblistener.sample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import com.zackratos.kblistener.kblistener.onKeyboardClose
import com.zackratos.kblistener.kblistener.onKeyboardOpen
import com.zackratos.ultimatebarx.ultimatebarx.UltimateBarX

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        UltimateBarX.with(this)
            .fitWindow(true)
            .colorRes(R.color.purple_700)
            .applyStatusBar()
        val rootView = findViewById<View>(R.id.root)
        rootView.onKeyboardOpen {
            Log.d("MainActivity", "onKeyboardOpen height == $it")
            toast("keyboard open \n height == $it")
            val lp = rootView.layoutParams
            lp.height = rootView.height - it
            rootView.layoutParams = lp
        }
        rootView.onKeyboardClose {
            Log.d("MainActivity", "onKeyboardClose height == $it")
            toast("keyboard close \n originHeight == $it")
            val lp = rootView.layoutParams
            lp.height = it
            rootView.layoutParams = lp
        }
    }

    private fun toast(content: String) {
        Toast.makeText(this, content, Toast.LENGTH_SHORT).show()
    }
}